UserDataSeeder.run   B
last analyzed

Complexity

Conditions 2

Size

Total Lines 73
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 66
dl 0
loc 73
ccs 3
cts 3
cp 1
crap 2
rs 8.1127
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import { DataSource } from 'typeorm';
2 7
import { User } from '../../users/entities/user.entity';
3
4 7
export default class UserDataSeeder {
5
  async run(connection: DataSource): Promise<void> {
6 9
    if (true) {
7
      //process.env.NODE_ENV !== 'production') {
8 9
      const userRepo = connection.getRepository(User);
9
10
      // Add example admin and test users
11 9
      await userRepo.save([
12
        {
13
          githubId: '149484382',
14
          username: 'Pbris',
15
          email: '[email protected]',
16
          roles: ['admin'],
17
          hasAcceptedTerms: true,
18
          isMonthlyPayment: false,
19
          accumulatedCost: 0,
20
          balance: 100,
21
        },
22
        {
23
          githubId: '149296874',
24
          username: 'airhelios',
25
          email: '[email protected]',
26
          roles: ['admin'],
27
          hasAcceptedTerms: true,
28
          isMonthlyPayment: true,
29
          accumulatedCost: 0,
30
        },
31
        {
32
          githubId: '13668660',
33
          username: 'KarlComSe',
34
          email: '[email protected]',
35
          roles: ['admin'],
36
          hasAcceptedTerms: true,
37
          isMonthlyPayment: true,
38
          accumulatedCost: 0,
39
        },
40
        {
41
          githubId: '149683406',
42
          username: 'gumme1',
43
          email: '[email protected]',
44
          roles: ['admin'],
45
          hasAcceptedTerms: true,
46
          isMonthlyPayment: true,
47
          accumulatedCost: 0,
48
        },
49
        {
50
          githubId: '123456789',
51
          username: 'johndoe',
52
          email: '[email protected]',
53
          roles: ['user'],
54
          hasAcceptedTerms: true,
55
          avatarUrl: 'https://example.com/john.jpg',
56
          isMonthlyPayment: true,
57
          accumulatedCost: 0,
58
        },
59
        {
60
          githubId: '234567890',
61
          username: 'janedoe',
62
          email: '[email protected]',
63
          roles: ['user', 'admin'],
64
          hasAcceptedTerms: true,
65
          avatarUrl: 'https://example.com/jane.jpg',
66
          isMonthlyPayment: true,
67
          accumulatedCost: 0,
68
        },
69
        {
70
          githubId: '345678901',
71
          username: 'bobsmith',
72
          email: '[email protected]',
73
          roles: ['user'],
74
          hasAcceptedTerms: false,
75
          avatarUrl: 'https://example.com/bob.jpg',
76
          isMonthlyPayment: true,
77
          accumulatedCost: 0,
78
        },
79
      ]);
80
    }
81
  }
82
}
83